package com.hq.stream;

import cn.hutool.core.collection.CollUtil;
import com.hq.stream.testdto.User;
import org.junit.Test;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.StreamSupport;


@SuppressWarnings("all")
public class StreamUser1ApiTest {
    static ArrayList<User> users ;
    static {
        users = CollUtil.toList(new User(1, "a"),
                new User(1, "a,b"),
                new User(2, "c,d"),
                new User(1, "a,c"));
    }
    @Test
    public void a(){
        // 数组创建Stream的方式
        int[] arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
        Arrays.stream(arr).map(i -> i * i)
                .filter(i -> i % 2 == 0)
                .forEach(System.out::println);

        System.out.println("=================");
// 直接对int序列创建Stream的方式
// 实际上这个方法就是调用了 Arrays.stream(arr);
        IntStream.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)
                .map(i -> i * i)
                .filter(i -> i % 2 == 0)
                .forEach(System.out::println);

        System.out.println("=================");
        Arrays.stream(arr).map(i -> i * i).forEach(a -> System.out.println(a));
    }


}
